package com.dhms.vostok1.database

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.dhms.vostok1.data.fault.FaultLevel
import com.dhms.vostok1.data.fault.FaultTypeItemData
import com.dhms.vostok1.data.spot_patrol.CheckInstrumentSpeedData
import com.dhms.vostok1.database.check_instrument.CheckInstrumentDao
import com.dhms.vostok1.database.fault.FaultDao

@Database(
    entities = [FaultLevel::class, FaultTypeItemData::class, CheckInstrumentSpeedData::class],
    version = 3,
    exportSchema = false
)
abstract class Vostok1Database : RoomDatabase() {
    abstract fun faultDao(): FaultDao
    abstract fun checkInstrumentDao(): CheckInstrumentDao

    companion object {
        @Volatile
        private var INSTANCE: Vostok1Database? = null

        private const val databaseName = "vostok1.db"

        fun getDatabase(context: Context): Vostok1Database {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context,
                    Vostok1Database::class.java,
                    databaseName
                )
//                    .createFromAsset("vostok1.db")
                    .build()
                // Database Path: /data/user/0/com.dhms.vostok1/databases/$databaseName
                INSTANCE = instance

                instance
            }
        }
    }
}